package com.community.owner.controller;

import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.exception.ServiceException;
import com.community.owner.domain.vo.OwnerBuildingsVO;
import com.community.owner.service.impl.OwnerBuildingServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/building")
public class OwnerBuildingController extends BaseController {

    @Autowired
    private OwnerBuildingServiceImpl buildingService;


    /**
     * 根据业主ID获取楼宇信息
     */
    @GetMapping("/getBuildingByOwnerId/{ownerId}")
    public AjaxResult getBuildingByOwnerId(@PathVariable Long ownerId) {
        try {
            OwnerBuildingsVO buildingVO = buildingService.getBuildingByOwnerId(ownerId);
            return AjaxResult.success(buildingVO);
        } catch (ServiceException e) {
            return AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            logger.error("获取楼宇信息失败", e);
            return AjaxResult.error("获取楼宇信息失败");
        }


    }


}
